<template>
<!--  首页-->
  <el-container style="height: 100%;">
    <el-aside width="250px" style="background-color: #f1f1f1">
      <div style="text-align: center">
        <el-avatar src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1527802161,1884555171&fm=26&gp=0.jpg" style="height: 100px;width: 100px;margin-top: 10px" ></el-avatar>
        <h3>{{userName}}</h3>
        <h5 @click="dialogVisible = true">社区：{{community}}</h5>

        <el-dialog
            :visible.sync="dialogVisible"
            width="50%"
            >

          <el-table
              :data="dialogVisibleData"
              style="width: 100%;"
          >
            <el-table-column
                prop="name"
                label="名称"
            >
            </el-table-column>
            <el-table-column
                prop="content"
                label="简介">
            </el-table-column>
            <el-table-column
                prop="address"
                label="社区地址"
                style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis"
            >
            </el-table-column>
            <el-table-column
                prop="selfAddress"
                label="自提点地址"
                style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis"
            >
            </el-table-column>
            <el-table-column
                prop="receiveName"
                label="联系人"
                style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis"
            >
            </el-table-column>
            <el-table-column
                prop="receiveMobile"
                label="联系方式"
                style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis"
            >
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                    size="mini"
                    @click="handleEdit(scope.$index, scope.row)">绑定</el-button>

              </template>
            </el-table-column>


          </el-table>
        </el-dialog>

        <el-menu
            default-active="img"
            class="el-menu-vertical-demo"
            :router="true"
            >

<!--          <el-menu-item index="img">-->
<!--            <i class="el-icon-s-home" ></i>-->
<!--            <span slot="title">首页</span>-->
<!--          </el-menu-item>-->
          <el-menu-item index="shop">
            <i class="el-icon-s-shop"></i>
            <span slot="title">店铺</span>
          </el-menu-item>
          <el-menu-item index="commodity">
            <i class="el-icon-s-goods"></i>
            <span slot="title">商品</span>
          </el-menu-item>
<!--          <el-menu-item index="type">-->
<!--            <i class="el-icon-menu"></i>-->
<!--            <span slot="title">类型</span>-->
<!--          </el-menu-item>-->
          <el-menu-item index="users">
            <i class="el-icon-user-solid"></i>
            <span slot="title">团长</span>
          </el-menu-item>
          <el-menu-item index="order">
            <i class="el-icon-s-ticket"></i>
            <span slot="title">订单</span>
          </el-menu-item>
          <el-menu-item index="audit">
            <i class="el-icon-s-data"></i>
            <span slot="title">审核</span>
          </el-menu-item>
          <el-menu-item index="deposit">
            <i class="el-icon-s-finance"></i>
            <span slot="title">余额</span>
          </el-menu-item>



        </el-menu>


        <el-button type="danger" round style="width: 200px;margin-top: 15px" @click="tuichu">退出登入</el-button>
      </div>
    </el-aside>
    <el-main style="padding: 0px">
      <router-view/>
    </el-main>
  </el-container>
</template>

<script>
import as from "@/axios/axios";
export default {
  name: "Home",

  created() {

    as.post("/manager/getCommunity").then((res)=>{
      this.community = res.data.message
      localStorage.setItem("community",res.data.message)
    })
    as.post("/community/getList").then((res)=>{
      console.log(res)
      this.dialogVisibleData = res.data.data
    })


  },
  data(){
    return{
      dialogVisibleData:"",
      dialogVisible:false,
      community:"",
      userName:localStorage.getItem("name"),
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },

  methods:{
    //退出登入
    tuichu(){
      localStorage.removeItem("token")
      localStorage.removeItem("name")
      localStorage.removeItem("community")
      this.$router.push('/login')
    },
    handleEdit(i,s){
      console.log(i)
      console.log(s)

      as.post("/manager/setCommunity",{'communityName':s.name}).then((res)=>{
        console.log(res)
        if(res.data == "绑定社区成功"){
          this.$message({
            message: res.data,
            type: 'success'
          });
          console.log(1111111)
          as.post("/manager/getCommunity").then((res)=>{
            this.community = res.data.message
            localStorage.setItem("community",res.data.message)
          })
        }else {
          // this.$message.error(res.data.message);
          console.log(2222222)
        }
      })
    }


  }
}
</script>

<style scoped>


</style>